//
//  UIBarButtonItem+Extensions.swift
//  tom微博
//
//  Created by tom king on 2017/8/17.
//  Copyright © 2017年 tom king. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    /// 创建 UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fonSize: fonSize 16
    ///   - target: target
    ///   - action: action
    ///   - isBack: 是否是返回按钮，如果是 加上箭头
    convenience init(title: String, fonSize: CGFloat = 16, target: AnyObject, action: Selector, isBack: Bool = false){
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: 16, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        
        if isBack{
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named:imageName), for: UIControlState(rawValue: 0))
            btn.setImage(UIImage(named:imageName + "_highlighted"), for: .highlighted)
            btn.sizeToFit()
        }
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        // self.init 实例化 UIBarButtonItem
        self.init(customView: btn)
        
    }
}

